// Achievement by G3X / GeXeH - Enjoy
// Version 1.0

// Achievement: Spend 5 total minutes off the ground in a vehicle.

local Value = achievements.GetValue( "Airtime", "total", 0 )

local function Update()

	if (Value != 300) then
		// print("Check Started.\n")
		local ply = LocalPlayer()
		local veh = ply:GetVehicle()
		local allowed = {"prop_vehicle_jeep", "prop_vehicle_airboat"}
		
		if (!ValidEntity( ply )) then return end
		
		if ( veh:IsValid() && (veh:WaterLevel() == 0) && table.HasValue( allowed, veh:GetClass() ) ) then
			local nearest = veh:NearestPoint( veh:GetPos() - Vector( 0, 0, 500 ) )
			local trace = util.TraceLine( { start = nearest, endpos = nearest - Vector( 0, 0, 20 ), mask = MASK_NPCWORLDSTATIC, filter = { ply, veh } } )
			if ( !trace.HitWorld ) then
			// print("Player Off Ground.\n")
			Value = math.Clamp( Value + 1, 0, 300 )
			achievements.SetValue( "Airtime", "total", Value )
			achievements.Update( "Airtime", Value / 300, string.FormattedTime( Value, "%02i:%02i" ) )
			// achievements.Update( "Airtime", Value / 300, Value .. "/300" )
			else
			// print("Player On Ground.\n")
			end
			
		// print("Check Ended.\n")
		end
	
	else
		timer.Destroy("Achievement.Airtime")
	end

end

timer.Create("Achievement.Airtime", 1, 0, Update)

achievements.Register( "Airtime", "Spend 5 total minutes off the ground in a vehicle.", "achievements/airtime", Value / 300, string.FormattedTime( Value, "%02i:%02i" ) )